function f=fun(x)
S_cooedinate =  [ 295.8040, 50, 0 ;
                    -104.6002, 281.1682, 0 ;
                    -191.1933, 231.1820, 0 ;
                    -191.1933, -231.1820, 0;
                    -104.6002, -281.1682, 0 ;%静平台连接点坐标
                    295.8040, -50, 0 ];
M_coordinate = [ 140.1144 , 142.7163, 0;  
                  53.5387, 192.7008, 0;
                  -193.6531, 49.9844, 0 ;
                  -193.6531, -49.9844, 0 ;
                  53.5387, -192.7008, 0 ;
                  140.1144 , -142.7163, 0 ];%动平台连接点在动坐标系的坐标
length=[570 513 355 384 447 399]; %给定杆1-6的长度，这个长度就是动静平台连接点之间的距离。单位mm
syms X Y Z A B G ;
for i=1:6
 M_TO_S_coordinate(i,1)= cos(G) * cos(B) * M_coordinate(i, 1) + (sin(A) * sin(B) * cos(G) - cos(A) *sin(G)) * M_coordinate(i, 2) + (cos(G) * sin(B) * cos(G) +sin(A) *sin(G)) * M_coordinate(i, 3) + X;
 M_TO_S_coordinate(i,2)= cos(B) *sin(G) * M_coordinate(i, 1) + (sin(A) * sin(B) * sin(G) +cos(A) * cos(G)) *M_coordinate(i, 2) +(cos(A) *sin(B) *sin(G) - sin(A) * cos(G)) * M_coordinate(i, 3) +Y;
M_TO_S_coordinate(i,3)= -sin(B) *  M_coordinate(i, 1) + sin(A) * cos(B) * M_coordinate(i, 2) + cos(A) *cos(B) *  M_coordinate(i, 3) + Z;
end %进行坐标变换，静动坐标系的动平台坐标转换为静坐标
for i=1:6
    F(i,1)=((M_TO_S_coordinate(i,1)- S_cooedinate(i,1))^2+(M_TO_S_coordinate(i,2)- S_cooedinate(i,2))^2+(M_TO_S_coordinate(i,3)- S_cooedinate(i,3))^2)^0.5-length(i);
end  %空间两点距离公式算杆长，建立方程组
 f=  F;